package exam.美团笔试;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/1 11:03
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int []nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        Arrays.sort(nums);
        long res = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            res += Math.abs(nums[i] - nums[i+1]);
        }
        System.out.println(res);
    }
}
